package edu.biwu.advice;

/**
 * @author 王俊彪
 * @version 1.0
 */

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 代表一个通知类
 * 通知类型：
 *  1。前置通知
 */
@Component
public class ServiceAdvice {

    public void beforeAdvice(){
        System.out.println("前置通知");
    }
    public void afterReturningAdvice(/*Object retval*/){
//        System.out.println("后置通知"+retval);
        System.out.println("后置通知");
    }
    public void finallyAdvice(){
        System.out.println("最终通知");
    }
    public void afterThrowingAdvice(JoinPoint joinPoint,Throwable throwable){
        System.out.println("#############"+throwable.getMessage());
        System.out.println("异常通知");
    }
    public Object aroundAdvice(ProceedingJoinPoint pjp){
        Object resval = null;
        try {
            System.out.println("前置通知");
            resval = pjp.proceed();
            System.out.println("环绕通知获取到的返回值 ："+resval);
            System.out.println("后置通知");
        } catch (Throwable e) {
            System.out.println("异常通知");
            throw new RuntimeException(e);
        } finally {
            System.out.println("最终通知");
            return resval;
        }


    }

}
